- name: AWS setup
  hosts: retrace_stg_aws
  user: root
  gather_facts: False

  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "{{ private }}/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  tasks:
    - import_tasks: "{{ tasks_path }}/aws_cloud.yml"
    - import_tasks: "{{ tasks_path }}/cloud_setup_basic.yml"


# fedora-messaging setup
- name: setup RabbitMQ
  hosts: rabbitmq[0]:rabbitmq_stg[0]
  user: root
  gather_facts: False
  tags: rabbitmq

  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - /srv/private/ansible/vars.yml
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles: 
  - role: rabbit/queue
    username: faf{{ env_suffix }}
    queue_name: faf
    routing_keys:
      - "org.fedoraproject.*.faf.report.threshold1"
      - "org.fedoraproject.*.faf.report.threshold10"
      - "org.fedoraproject.*.faf.report.threshold100"
      - "org.fedoraproject.*.faf.report.threshold1000"
      - "org.fedoraproject.*.faf.report.threshold1000"
      - "org.fedoraproject.*.faf.report.threshold10000"
      - "org.fedoraproject.*.faf.report.threshold100000"
      - "org.fedoraproject.*.faf.report.threshold1000000"
      - "org.fedoraproject.*.faf.problem.threshold1"
      - "org.fedoraproject.*.faf.problem.threshold10"
      - "org.fedoraproject.*.faf.problem.threshold100"
      - "org.fedoraproject.*.faf.problem.threshold1000"
      - "org.fedoraproject.*.faf.problem.threshold1000"
      - "org.fedoraproject.*.faf.problem.threshold10000"
      - "org.fedoraproject.*.faf.problem.threshold100000"
      - "org.fedoraproject.*.faf.problem.threshold1000000"
    sent_topics: ^org\.fedoraproject\.{{ env_short }}\.faf\..*

- name: Setup retrace hosts
  hosts: retrace,retrace_stg
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "{{ private }}/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  pre_tasks:
    - import_tasks: "{{ tasks_path }}/yumrepos.yml"
      when: datacenter != 'aws'

  tasks:
    - import_role: name=base
    - import_role: name=hosts
    - import_role: name=openvpn/client
    - import_role: name=ipa/client
      when: env != 'staging'
    - import_role: name=rkhunter
    - import_role: name=nagios_client
    - import_role: name=sudo

    - import_tasks: "{{ tasks_path }}/motd.yml"

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"

- name: setup FAF server
  hosts: retrace,retrace_stg
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "{{ private }}/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  tasks:
    - import_role: name=abrt/faf-pre
    - import_role: name=abrt/faf
      vars:
        faf_web_on_root: false
        faf_admin_mail: msuchy@redhat.com
        faf_web_openid_privileged_teams: "provenpackager,proventesters"
        faf_web_secret_key: "{{fedora_faf_web_secret_key}}"
        faf_spool_dir: /srv/faf/
    - import_role: name=abrt/faf-post

- name: setup retrace server
  hosts: retrace,retrace_stg
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "{{ private }}/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  tasks:
    - import_role: name=abrt/retrace-pre
    - import_role: name=abrt/retrace
      vars:
        rs_require_gpg_check: false
        rs_max_parallel_tasks: 12
        rs_max_packed_size: 1024
        rs_max_unpacked_size: 1280
        rs_min_storage_left: 1280
        rs_delete_task_after: 8
        rs_delete_failed_task_after: 1
        rs_repo_dir: /srv/retrace/repos
        rs_save_dir: /srv/retrace/tasks
        rs_faf_link_dir: /srv/retrace/hardlink-local
        hostname: "{{ public_hostname }}"
        faf_spool_dir: /srv/faf
        faf_fedmsg_ca_cert: /etc/fedora-messaging/faf/ca.crt
        faf_fedmsg_keyfile: /etc/fedora-messaging/faf/faf.key
        faf_fedmsg_certfile: /etc/fedora-messaging/faf/faf.crt
    - import_role: name=abrt/retrace-post
